package com.huluobo.a2206douyindemo.adapter;

import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.huluobo.a2206douyindemo.R;
import com.huluobo.a2206douyindemo.live.MessageEntity;
import com.huluobo.a2206douyindemo.utils.ImageUtils;
import com.huluobo.base.bean.CommentBeanResult;

import java.util.List;

/**
 * Created by LC on 2024/8/20.
 */
public class CommentAdapter extends BaseQuickAdapter<CommentBeanResult.CommentBean, BaseViewHolder> {
    private ResponseAdapter responseAdapter = new ResponseAdapter();

    public CommentAdapter(@Nullable List<CommentBeanResult.CommentBean> data) {
        super(R.layout.item_comment, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, CommentBeanResult.CommentBean commentBean) {
        ImageUtils.getInstance().loadCircleImage(getContext(), commentBean.getIcon(),
                baseViewHolder.getView(R.id.item_comment_icon_iv));
        baseViewHolder.setText(R.id.item_comment_name_tv, commentBean.getUsername());
        baseViewHolder.setText(R.id.item_comment_msg_tv, commentBean.getMsg());
        baseViewHolder.setText(R.id.item_comment_time_tv, commentBean.getCreatetime());

        RecyclerView recyclerView = baseViewHolder.getView(R.id.item_comment_response_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(responseAdapter);
        TextView resTv = baseViewHolder.getView(R.id.item_comment_response_tv);
        resTv.setOnClickListener(v -> {
            responseAdapter.getData().add(new MessageEntity("LC", "回复了一条消息"));
            responseAdapter.notifyDataSetChanged();
        });
    }
}
